//
//  CaiWuManageViewController.m
//  LazyCat
//
//  Created by jike on 15/12/30.
//  Copyright (c) 2015年 zhanshu. All rights reserved.
//

#import "CaiWuManageViewController.h"
#import "CaiWuTableViewCell.h"
#import "OtherTableCell.h"
#import "html5MYViewController.h"
#import "myWebViewController.h"

@interface CaiWuManageViewController ()<UITableViewDataSource,UITableViewDelegate>
{
    UITableView *_tableView;
    UIView *_headView; // 头部view
    UILabel *_moneyLable; // 今日收益
}
@end

@implementation CaiWuManageViewController

-(void)viewWillAppear:(BOOL)animated {
    if (kNetworkNotReachability) { // 没网
        [[MessShowView share] showWithMess:@"当前网络不给力"];
        _moneyLable.text = @"0.00";
        return;
    }
    float money = [[ShopCommonModel share].todaytotalmoney floatValue];
    _moneyLable.text = [NSString stringWithFormat:@"%.2f",money];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    [self createTable];
}
-(UIStatusBarStyle)preferredStatusBarStyle {//修改状态栏的颜色
    return UIStatusBarStyleLightContent;
}
-(void)createTable {
    _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeight) style:UITableViewStyleGrouped];
    _tableView.delegate = self;
    _tableView.dataSource = self;
    [self.view addSubview:_tableView];
    
    _headView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, 175)];
    _headView.backgroundColor = MainColor;
    UIImageView *imv = [[UIImageView alloc] initWithFrame:CGRectMake(10, 30, 12, 21)];
    imv.image = [UIImage imageNamed:@"lALOCzPrgiYW_22_38"];
    [_headView addSubview:imv];
    UIButton *cancelBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    cancelBtn.frame = CGRectMake(5, 20, 60, 40);
    [cancelBtn addTarget:self action:@selector(backAction) forControlEvents:UIControlEventTouchUpInside];
    [_headView addSubview:cancelBtn];
    
    UILabel *titleLable = [[UILabel alloc] initWithFrame:CGRectMake(0, 32, ScreenWidth, 20)];
    titleLable.text = @"财务管理"; 
    titleLable.font = [UIFont systemFontOfSize:18];
    titleLable.textAlignment = NSTextAlignmentCenter;
    titleLable.textColor = [UIColor whiteColor];
    [_headView addSubview:titleLable];
    
    UIView *lineV = [[UIView alloc]initWithFrame:CGRectMake(0, 64, ScreenWidth, 1)];
    lineV.hidden = YES;
    lineV.backgroundColor = SetColor(38, 157, 213, 1);
    [_headView addSubview:lineV];
    
    UILabel *totdayMoney = [[UILabel alloc] initWithFrame:CGRectMake(0, 82, ScreenWidth, 30)];
    totdayMoney.textAlignment = NSTextAlignmentCenter;
    totdayMoney.font = [UIFont systemFontOfSize:21];
    totdayMoney.textColor = [UIColor whiteColor];
    totdayMoney.text = @"今日总收益(元)";
    [_headView addSubview:totdayMoney];
    
    _moneyLable = [[UILabel alloc] initWithFrame:CGRectMake(0, 110, ScreenWidth, 30)];
    _moneyLable.textAlignment = NSTextAlignmentCenter;
    _moneyLable.font = [UIFont systemFontOfSize:19];
    _moneyLable.textColor = [UIColor whiteColor];
    float money = [[ShopCommonModel share].todaytotalmoney floatValue];
    _moneyLable.text = [NSString stringWithFormat:@"%.2f",money];
    [_headView addSubview:_moneyLable];
    
    UILabel *wenLabel = [[UILabel alloc]initWithFrame:CGRectMake(ScreenWidth-115, 140, 110, 30)];
    wenLabel.textColor = SetColor(128, 198, 231, 1);
    wenLabel.text = @"如何计算今日收益?";
    wenLabel.font = [UIFont systemFontOfSize:12];
    [_headView addSubview:wenLabel];
    
    UIImageView *wenhaoImg = [[UIImageView alloc]initWithFrame:CGRectMake(ScreenWidth-135, 148, 15, 15)];
    wenhaoImg.image = [UIImage imageNamed:@"wenhao_27_27"];
    [_headView addSubview:wenhaoImg];
    
    UIView *v2 = [[UIView alloc]initWithFrame:CGRectMake(ScreenWidth-135, 140, 130, 30)];
    [_headView addSubview:v2];
    
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(shuoming)];
    [v2 addGestureRecognizer:tap];
    tap.cancelsTouchesInView = NO;
    
    _tableView.tableHeaderView = _headView;
}
-(void)shuoming {
    myWebViewController*html5Vc = [[myWebViewController alloc] init];
    html5Vc.titleName = @"如何计算今日收益?";
    [self.navigationController pushViewController:html5Vc animated:YES];
}
-(void)backAction {
    [self.navigationController popViewControllerAnimated:YES];
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    if (section == 0) {
        return 0.01;
    }else{
        return 10;
    }
}
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    return 0.0001;
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 2;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    if (section == 0) {
        return 1;
    }else {
        return 4;
    }
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 44;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *Cell = @"cell";
    OtherTableCell *cell = [tableView dequeueReusableCellWithIdentifier:Cell];
    if (!cell) {
        cell = [[[NSBundle mainBundle] loadNibNamed:@"OtherTableCell" owner:self options:nil] firstObject];
    }
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.img.frame = CGRectMake(15, 15, 26, 20);
    cell.titleLable.frame = CGRectMake(15, 12, ScreenWidth - 100, 20);
    NSArray *arr = [NSArray array];
    arr = @[@[@"成为懒猫社长,获得更大收益!"],@[@"订单支付明细",@"扫码收款订单",@"销卡记录",@"会员卡消费记录"]];
    cell.titleLable.text = [NSString stringWithFormat:@"%@",arr[indexPath.section][indexPath.row]];
    cell.titleLable.textColor = SetColor(37, 37, 37, 1);
    return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    if (kNetworkNotReachability) { // 没网
        [[MessShowView share] showWithMess:@"当前网络不给力"];
        return;
    }
    if (indexPath.section == 1) {
        if (indexPath.row == 0){//订单支付明细
            myWebViewController*html5Vc = [[myWebViewController alloc] init];
            html5Vc.titleName = @"订单支付明细";
            html5Vc.requestUrl = [NSString stringWithFormat:shoukuanM,[AppData share].username,[Utils md5SignStr]];
            NSLog(@"11:%@",html5Vc.requestUrl);
            [self.navigationController pushViewController:html5Vc animated:YES];
        }else if (indexPath.row == 1){//收款明细
            NSUserDefaults *userDefaul = [NSUserDefaults standardUserDefaults];
            NSString *iptype = [userDefaul objectForKey:@"iptype"];
            NSString *banben = [userDefaul objectForKey:@"banben"];
            myWebViewController*html5Vc = [[myWebViewController alloc] init];
            html5Vc.titleName = @"扫码收款订单";
            html5Vc.requestUrl = [NSString stringWithFormat:scanForPayOrderListUrl,[AppData share].username,[Utils md5SignStr],iptype,banben];
            [self.navigationController pushViewController:html5Vc animated:YES];
            
        }
        else if (indexPath.row == 2){
            myWebViewController*html5Vc = [[myWebViewController alloc] init];
            html5Vc.titleName = @"销卡记录";
            [self.navigationController pushViewController:html5Vc animated:YES];
        }else {
            myWebViewController*html5Vc = [[myWebViewController alloc] init];
            html5Vc.titleName = @"会员卡消费记录";
            [self.navigationController pushViewController:html5Vc animated:YES];
        }
    }else {
        myWebViewController*html5Vc = [[myWebViewController alloc] init];
//        html5Vc.titleName = @"成为懒猫社长,获得更大收益!";
//#define zhaoshangM BaseUrl @"/Zhaoshang.html?username=%@&sign2=%@&plat=ios"
//#define zhaoshangM BaseUrl @"/Zhaoshang.html?username=%@&sign2=%@&plat=ios&identity=%@&terminal=%@&OSVersion=%@"

        NSUserDefaults *userDefaul = [NSUserDefaults standardUserDefaults];
        NSString *iptype = [userDefaul objectForKey:@"iptype"];
        NSString *banben = [userDefaul objectForKey:@"banben"];
        
        html5Vc.requestUrl = [NSString stringWithFormat:zhaoshangM,[AppData share].username,[Utils md5SignStr],iptype,banben];
        NSLog(@"%@",html5Vc.requestUrl);
        [self.navigationController pushViewController:html5Vc animated:YES];
    }
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}
@end
